We’re going to look at the Instacart data
library(tidyverse)
library(p8105.datasets)
library(plotly)
data("instacart")
instacart_df = instacart
instacart_df =
instacart %>%
mutate(
department = as.factor(department),
aisle = as.factor(aisle),
order_dow = factor(order_dow,
levels = 0:6,
labels = c("Sun","Mon","Tue","Wed","Thu","Fri","Sat"))) %>%
sample_n(1000)
instacart_bar =
instacart_df %>%
count(department) %>%
mutate(department = fct_reorder(department, n)) %>%
plot_ly(
x = ~department,
y = ~n,
color = ~department,
type = "bar",
colors = "viridis") %>%
layout(
title = "Most Frequently Ordered Departments",
xaxis = list(title = "Department"),
yaxis = list(title = "Number of Products Ordered")
)
instacart_bar
instacart_box =
instacart %>%
filter(department %in% c("produce", "snacks", "dairy eggs", "frozen", "beverages")) %>%
mutate(department = fct_reorder(department, order_hour_of_day)) %>%
plot_ly(
x = ~department,
y = ~order_hour_of_day,
color = ~department,
type = "box",
colors = "viridis") %>%
layout(
title = "Distribution of Order Hour by Top 5 Departments",
xaxis = list(title = "Department"),
yaxis = list(title = "Hour of Day Order was Placed")
)
instacart_box